Placeholder Formats
When working with translations, handling placeholders correctly is crucial for proper formatting and localization. Different platforms and languages use different placeholder syntaxes. Here’s an overview of common placeholder formats and how they map to the ICU Message Format, which is the native and most powerful format supported by many modern localization tools.
Overview
Our platform supports multiple placeholder syntaxes commonly used in different ecosystems, converting them to and from ICU Message Format for consistent handling:
Placeholder Format | Description | Notes |
---|---|---|
ICU Message Format | Native powerful format for localization like {varName} . Example usage Hello, {name}. | This format is the default format used by SejHey internally. |
PHP sprintf | Standard PHP placeholders like %s , %d | Limited specifiers supported, no advanced flags. |
Java String.format | Java’s format specifiers (%s , %d , %f ) | Similar limitations as PHP sprintf. |
C sprintf | C-style placeholders, similar to PHP/Java | Limited specifiers, no advanced flags. |
Apple sprintf | Apple-specific format placeholders (%@ , %lld ) | Supports positional specifiers and %@ . |
Ruby sprintf | Ruby format with named and positional placeholders | Supports named placeholders like %<name>s . |
Common Placeholder Specifiers Supported
Specifier | ICU Equivalent | Description | Notes |
---|---|---|---|
% | % | Literal percent sign | %% in source maps to % in ICU and back when exporting. |
s | {0} | String placeholder | Represents a simple string. |
d | {0, number} | Integer number | Converts numeric integer specifiers to ICU number format. |
f | {0, number, 0.000000} | Floating point with default precision | Defaults to 6 decimal places, e.g. %f → 0.000000 . Custom precision like %.2f → 0.00 . |
e | {0, number, scientific} | Scientific notation number | %e supported, but %E (uppercase) is not supported. |
@ (Apple only) | {0} | Object placeholder | Used in Apple format strings; can be used for generic placeholders. |
Named placeholders (Ruby only) | {name} or {name, type} | Named argument placeholders | Ruby supports named placeholders such as %<name>s . |
Positional Specifiers
Most formats support positional placeholders, e.g., %2$s
or %1$d
. These are converted into zero-based ICU placeholders, e.g.:
I am %2$s and have %1$d dogs.
→I am {1} and have {0, number} dogs.
Details by Format
ICU Message Format
- Native format, no conversion needed.
- Supports advanced features like plurals, selects, and nested messages.
PHP sprintf
- Supported specifiers:
%
,s
,d
,f
,e
. - No support for additional flags/modifiers (like width or padding).
- Positional specifiers like
%2$s
supported and converted.
Java String.format
- Same supported specifiers and limitations as PHP sprintf.
C sprintf
- Same supported specifiers and limitations as PHP sprintf.
Apple sprintf
- Supports
%@
(generic placeholder),%lld
(64-bit number), and positional specifiers. - No advanced flags/modifiers supported.
Ruby sprintf
- Supports named placeholders, e.g.,
%<name>s
. - Supports positional specifiers.
- Same limited specifier set:
%
,s
,d
,f
,e
.
Notes
- Unsupported or complex flags and modifiers in placeholders are not converted and may cause issues.
- For unsupported placeholder types, use generic placeholders like
%@
(Apple) or{0}
(ICU) and handle formatting in code. - Always test your placeholders after importing/exporting to avoid runtime formatting errors.
This mapping ensures your translations stay consistent and placeholders work correctly regardless of the source or target format.